package com.sf.study.dubbo.producer.biz.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.sf.study.dubbo.servport.biz.IUserBiz;
import com.sf.study.dubbo.servport.pojo.User;

@Service
public class UserBiz implements IUserBiz {

    private static final Map<String, User> users = new HashMap<>();
    
    static {
        users.put("hayden", new User("hayden", 23, new Date()));
        users.put("chenchen", new User("chenchen", 23, new Date()));
        users.put("fangfang", new User("fangfang", 23, new Date()));
        users.put("ganggang", new User("ganggang", 23, new Date()));
    }
    
    @Override
    public User getUserByName(String name) {
        return users.get(name);
    }
    
    @Override
    public List<User> getUserList() {
        return new ArrayList<>(users.values());
    }
    
    @Override
    public Map<String, User> getUserMap() {
        return users;
    }
    
    @Override
    public void saveOrUpdate(User user) {
        users.put(user.getName(), user);
    }
    
    @Override
    public void delete(String name) {
        users.remove(name);
    }
    
}
